<template>
	<view class="view-contain">
		<!-- 公共组件-每个页面必须引入 -->
		<public-module leftIcon="arrow-left" :title="title" />
		<view class="content">
			<rich-text :nodes="wrapContent|formatRichText" />
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
      title: '大神经验',
      wrapContent: ''
		}
	},
	filters:{
		formatRichText(html) { //控制小程序中图片大小
			if (html) {
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {      
					if(match.search(/style=/gi) == -1){
						match = match.replace(/\<img/gi,'<img style=""')
					}
					return match
				})
			
				newContent = newContent.replace(/style="/gi, '$& max-width:100% !important;')
				return newContent
			}
		}
  },
  onLoad(option) {
    if (option.content) {
      const content = decodeURIComponent(option.content)
      const convertedContent = content.replace(/<pre/g, '<div').replace(/<\/pre>/g, '</div>')
			this.wrapContent = `<div style="word-wrap: break-word; white-space: pre-wrap;">${convertedContent}</div>`
    }
  },
	methods: {}
}
</script>

<style lang="scss" scoped>
.view-contain {
	position: relative;
	height: 100vw;
	
	.content {
		padding: 24rpx 24rpx;
		
	}

}
</style>